

// events 事件机制 
// emit 发送事件
// on   监听事件
// once 只执行一次

const EventEmitter=require('events')
const { EventEmitter } = require('stream')

//ES5 子类继承父类
function Player(){
    EventEmitter.call(this)
}

Player.prototype=new EventEmitter();

//ES6
  class Myplayer extends EventEmitter{

  }
  const p1 = new Player()

  //p1事件代理对象
//   p1.emit("wh2114","今天写代码")
  p1.on("wh2114likes",msg=>{
   console.log(msg);
  }) 
  


   p1.once("wh2114todos",msg=>{
    console.log(msg);
   }) 

  p1.emit("wh2114likes","今天写代码")

  p1.emit("wh2114todos","今天也要写代码")
  p1.emit("wh2114todos","今天也要写代码")